/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package adapdateurs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author BENAMMAR Riyadh
 */
public class PaysCSV implements Adapdateur{
    String pays;
    @Override
    public String traduire(String requete) {
        String aRetourner=requete;
        return aRetourner;
    }

    @Override
    public List executerRequete(String requete) {
        List<String> resultat=new ArrayList<>();
        boolean villes=requete.endsWith("villes")?true:false;
        if(villes)pays=requete.substring(0, requete.indexOf(":"));
        BufferedReader br=null;
        try{
            br=new BufferedReader(new FileReader(new File("ressources/pays_villes.csv")));
            br.readLine();
            while(br.ready()){
                String [] data=br.readLine().split(";");
                //System.out.println("data: "+data[0]);
                if(requete.equalsIgnoreCase("pays"))
                resultat.add(data[0]);
                else if(data[0].equalsIgnoreCase(pays))resultat.add(data[1]);
            }
        }catch(IOException ex){
            ex.printStackTrace();
        }
                
        return resultat;
    }
    
}
